/**
 *====================================================
 * 文件名称: FinanceAuditServiceImpl.java
 * 修订记录：
 * No    日期				作者(操作:具体内容)
 * 1.    2015年09月23日	chenxy(创建:创建文件)
 *====================================================
 * 类描述：(说明未实现或其它不应生成javadoc的内容)
 */
package com.yuexunit.finance.project.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.yuexunit.finance.project.entity.FinanceGroupEntity;
import com.yuexunit.finance.project.entity.FinanceGroupMemberEntity;
import com.yuexunit.inject.annotation.Implements;
import com.yuexunit.persist.PersistUtil;

/**
 * @ClassName: FinanceGroupServiceImpl
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author chenxy
 * @date 2015年09月23日 18:56:17
 */
@Implements(FinanceGroupService.class)
public class FinanceGroupServiceImpl implements FinanceGroupService {

	@Override
	public Long createFinanceGroupEntity(FinanceGroupEntity entity) {
		PersistUtil.insert(entity);
		return entity.getId();
	}

	@Override
	public Long createFinanceGroupMemberEntity(FinanceGroupMemberEntity entity) {
		PersistUtil.insert(entity);
		return entity.getId();
	}

	@Override
	public List<FinanceGroupEntity> inquireFinanceGroupEntityList() {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceGroupEntity.class);
		criteria.addOrder(Order.desc("createDate"));
		return PersistUtil.get(criteria);
	}

	@Override
	public List<FinanceGroupMemberEntity> inquireFinanceGroupMemberEntityList(
			String groupId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceGroupMemberEntity.class);
		criteria.add(Restrictions.eq("groupId", groupId));
		criteria.addOrder(Order.desc("createDateTime"));
		return PersistUtil.get(criteria);
	}

	@Override
	public void deleteFinanceGroupMember(Long emp, String groupId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceGroupMemberEntity.class);
		criteria.add(Restrictions.eq("empId", emp));
		criteria.add(Restrictions.eq("groupId", groupId));
		
		List<FinanceGroupMemberEntity> list = PersistUtil.get(criteria);
		for (FinanceGroupMemberEntity p : list) {
			PersistUtil.delete(p);
		}
		
	}

	@Override
	public void deleteFinanceGroup(String groupId) {
		DetachedCriteria criterias = DetachedCriteria.forClass(FinanceGroupEntity.class);
		criterias.add(Restrictions.eq("groupId", groupId));
		List<FinanceGroupEntity> emplist =PersistUtil.get(criterias);
		if(emplist!=null && emplist.size()>0)
		PersistUtil.delete(emplist.get(0));  //删除群组
		
		
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceGroupMemberEntity.class);
		criteria.add(Restrictions.eq("groupId", groupId));
		List<FinanceGroupMemberEntity> list =PersistUtil.get(criteria);
		if(list!=null && list.size()>0)
		for (FinanceGroupMemberEntity p : list) {
			PersistUtil.delete(p);//删除群组员工
		}
	}

}
